<template>
  <div class="users">
    <h1>用户列表</h1>
    <div class="goodList">
      <el-table :data="tableData" border style="width: 100%" max-height="700">
        <el-table-column prop="id" label="ID" width="auto">
        </el-table-column>
        <el-table-column prop="username" label="用户名" width="auto">
        </el-table-column>
        <el-table-column prop="email" label="邮箱" width="auto">
        </el-table-column>
        <el-table-column prop="phone" label="电话" width="auto">
        </el-table-column>
        <el-table-column prop="createTime" label="注册时间" width="auto">
          <template slot-scope="scope">
            {{scope.row.createTime | getTime}}
          </template>
        </el-table-column>
      </el-table>
      
      <!-- 分页 -->
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="pageData.pageNum"
          :page-size="pageData.pageSize"
          layout="prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { users } from "../api/index"
import { happenTimeFun } from "../utils/mounted"
export default {
  name: "usersy",
  data() {
    return {
      currentPage3: 5,
      tableData: [],
      pageData:{
        pageSize:10,
        pageNum:1,
      },
      total:0
    };
  },
  created(){
    this.init(this.pageData)
  },
  filters:{
    getTime(val){
      return happenTimeFun(val)
    }
  },
  methods: {
    init(val){
      users({pageNum:val.pageNum,pageSize:val.pageSize}).then(res=>{
        console.log(res);
        this.tableData = res.data.list
        this.total = res.data.total
      })
    },
    handleClick(row) {
      console.log(row);
    },
    handleSizeChange(val) {
      this.pageData.pageSize = val
      this.init(this.pageData)
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.pageData.pageNum = val
      this.init(this.pageData)
      console.log(`当前页: ${val}`);
    },
  },
};
</script>

<style scoped lang="scss">
</style>